import http from "@/api";
import { IdList, ResultData } from "../interface";

export namespace element {
  export interface ElementSearchVo {
    title: string; // 菜单名称
    type: string; // 菜单类型
  }
  export interface ElementInsertVo {
    parentId: string; // 父元素编号
    name: string; // 元素名称
    path: string; // 菜单路径
    component: string; // 组件位置
    redirect: string; // 菜单路径重定向
    icon: string; // 菜单图标
    title: string; // 菜单标题
    activeMenu: string; // 当前路由为详情页时，需要高亮的菜单
    isLink: string; // 外链地址
    isHide: boolean; // 是否隐藏 0-否 1-是
    isFull: boolean; // 是否可以全屏 0-否 1-是
    isAffix: boolean; // 是否固定在标签页不可关闭 0-否 1-是
    isKeepAlive: boolean; // 是否缓存路由 0-否 1-是
    type: string; // 元素类型  0-菜单 1-按钮
    code: string; // 按钮唯一编码
    remark: string; // 备注
    orderNum: number; // 排序
  }
  export interface ElementUpdateVo {
    elementId: string; // 元素编号
    parentId: string; // 父元素编号
    name: string; // 元素名称
    path: string; // 菜单路径
    component: string; // 组件位置
    redirect: string; // 菜单路径重定向
    icon: string; // 菜单图标
    title: string; // 菜单标题
    activeMenu: string; // 当前路由为详情页时，需要高亮的菜单
    isLink: string; // 外链地址
    isHide: boolean; // 是否隐藏 0-否 1-是
    isFull: boolean; // 是否可以全屏 0-否 1-是
    isAffix: boolean; // 是否固定在标签页不可关闭 0-否 1-是
    isKeepAlive: boolean; // 是否缓存路由 0-否 1-是
    type: string; // 元素类型  0-菜单 1-按钮
    remark: string; // 备注
    orderNum: number; // 排序
  }
  export interface Element {
    elementId: string;
    parentId: string;
    name: string;
    path: string;
    component: string;
    redirect: string;
    icon: string;
    title: string;
    activeMenu: string;
    isLink: string;
    isHide: boolean;
    isFull: boolean;
    isAffix: boolean;
    isKeepAlive: boolean;
    type: string;
    code: string;
    createTime: Date;
    createUserId: string;
    updateTime: Date;
    updateUserId: string;
    remark: string;
    orderNum: number;
    isDeleted: boolean;
  }
}
/**
 * 获取角色菜单权限
 */
export const getRoleElement = (roleId: string) => {
  return http.get<ResultData>("/admin/roleElement/getRoleElement", { roleId: roleId });
};

/**
 * 获取菜单树
 */
export const getElementsTree = (roleId: string) => {
  return http.get<ResultData>("/admin/element/getElementsTree", { roleId: roleId });
};

export const saveRoleElements = (idList: IdList) => {
  return http.post<ResultData>("/admin/roleElement/saveRoleElements", idList);
};

export const getElements = (params: element.ElementSearchVo) => {
  return http.post<ResultData>("/admin/element/getElements", params);
};

// 添加元素
export const addElement = (params: element.ElementInsertVo) => {
  return http.post("/admin/element/insert", params);
};

// 修改元素
export const updateElement = (params: element.ElementUpdateVo) => {
  return http.post("/admin/element/update", params);
};

// 删除元素
export const deleteElement = (id: string) => {
  return http.delete("/admin/element/delete", { id: id });
};

// 根据Id查询角色
export const getElementById = (id: string) => {
  return http.get<element.Element>("/admin/element/selectById", { id: id });
};
